students = []

while True:
    print("\n学生信息管理系统")
    print("1. 添加学生信息")
    print("2. 删除学生信息")
    print("3. 修改学生信息")
    print("4. 查询所有学生信息")
    print("5. 退出系统")

    choice = input("请输入功能序号(1-5)：")

    if choice == "1":
        name = input("请输入学生姓名：")
        gender = input("请输入学生性别：")
        phone = input("请输入学生手机号：")
        # 序号为列表长度+1（按添加顺序排序）
        student = {"序号": len(students) + 1, "姓名": name, "性别": gender, "手机号": phone}
        students.append(student)
        print("添加成功！")

    elif choice == "2":
        if not students:
            print("学生信息表为空")
            continue
        del_num = int(input("请输入要删除的学生序号："))
        del_index = None
        for i, s in enumerate(students):
            if s["序号"] == del_num:
                del_index = i
                break
        if del_index is not None:
            students.pop(del_index)
            for i in range(len(students)):
                students[i]["序号"] = i + 1
            print("删除成功！")
        else:
            print("未找到该序号的学生")


    elif choice == "3":
        if not students:
            print("学生信息表为空")
            continue
        mod_num = int(input("请输入待修改学生的序号："))
        mod_student = None
        for s in students:
            if s["序号"] == mod_num:
                mod_student = s
                break
        if mod_student:
            new_name = input("请输入修改后的姓名：")
            new_gender = input("请输入修改后的性别：")
            new_phone = input("请输入修改后的手机号：")
            mod_student["姓名"] = new_name
            mod_student["性别"] = new_gender
            mod_student["手机号"] = new_phone
            print("修改成功！")
        else:
            print("未找到该序号的学生")

    elif choice == "4":
        if not students:
            print("学生信息表为空")
            continue
        print("\n所有学生信息如下：")
        print(f"{'序号':<5}{'姓名':<10}{'性别':<5}{'手机号':<15}")
        print("-" * 35)
        for s in students:
            print(f"{s['序号']:<5}{s['姓名']:<10}{s['性别']:<5}{s['手机号']:<15}")

    elif choice == "5":
        print("已退出学生信息管理系统")
        break

    else:
        print("输入错误，请重新输入1-5之间的序号！")